package org.wattdepot.cli.command;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

/**
 * Tests the ListSensorDataTSP class.
 * 
 * @author Yichi Xu
 *
 */
public class TestSensorDataCommand extends CommandTestBed {
  /** 
   * Tests the doCommand method of ListSensorDataTSPCommand.
   * 
   * @see org.wattdepot.cli.command.CommandTestBed#testDoCommand()
   */
  @Test
  @Override
  public void testDoCommand() {
    String command;
    String result;
    
    SensorDataCommand listCommand = new SensorDataCommand(this.client);
    
    //Sad tests
    //Correct input "list sensordata SIM_KAHE_1 timestamp 2009-11-01T00:00:00.000-10:00"
    command = "sensordata SIM_KAHE_1 foo 2009-11-01T00:00:00.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the command is invalid.", 
        result.startsWith(WattDepotCliCommand.PARAMETER_ERROR));
 
    command = "sensordata SIM_KAHE_1 timestamp 2009-11-01T00:00:00.000-10:00 foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the command is invalid.", 
        result.startsWith(WattDepotCliCommand.PARAMETER_COUNT_ERROR));
    
    command = "sensordata foo timestamp 2009-11-01T00:00:00.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the source is invalid.", 
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
    
    command = "sensordata SIM_KAHE_1 timestamp foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that the timestamp is invalid.", 
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    
    //Happy tests
    command = "sensordata SIM_KAHE_1 timestamp 2009-11-01T00:00:00.000-10:00";
    result = listCommand.doCommand(command);
    assertTrue("Checking that there is a result for the query",
        result.contains("Tool"));
    assertFalse("Checking that the command is valid.",
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the connection is fine.",
        result.equals(WattDepotCliCommand.CONNECTION_ERROR));
    assertFalse("Checking that the input converts to timestamp correctly.",
        result.startsWith(WattDepotCliCommand.TSTAMP_ERROR));
    assertFalse("Checking that the source is invalid.", 
        result.startsWith(WattDepotCliCommand.SOURCE_ERROR));
  }
}
